package com.cakin.javademo;

/**
 * @ClassName: TestDemo1
 * @Description: TODO
 * @Date: 2020/6/13
 * @Author: cakin
 */
public class TestDemo1 {
    public static void main(String[] args) {
        int a = 60;     /* 60 = 0011 1100 */
        int b = 13;     /* 13 = 0000 1101 */
        int c = 0;
        c = a & b;
        System.out.println("a & b = " + c );  // 00001100

        c = a | b;
        System.out.println("a | b = " + c );  // 00111101

        c = a ^ b;
        System.out.println("a ^ b = " + c );  // 00110001

        c = ~a;
        System.out.println("~a = " + c );     // 11000011

        // 移动运算不会改变a的值
        c = a << 2;
        System.out.println("a << 2 = " + c );  // 11110000

        c = a >> 2;
        System.out.println("a >> 2  = " + c ); // 00001111

        c = a >>> 2;     /* 15 = 0000 1111 */
        System.out.println("a >>> 2 = " + c );  // 00001111

        boolean a1 = true;
        boolean b1 = false;
        System.out.println("a && b = " + (a1&&b1)); //false
        System.out.println("a || b = " + (a1||b1) ); //true
        System.out.println("!(a && b) = " + !(a1 && b1)); //true

        int a2 = 5; //定义一个变量；
        boolean b2 = (a2<4)&&(a2++<10);
        System.out.println("使用短路逻辑运算符的结果为"+b2); // false
        System.out.println("a的结果为"+a2); // 5
    }
}
